package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.View;

import com.lottery.ruok.lottrey.adapter.recyclleradapter.BaseAppRecyclerViewAdapter;
import com.lottery.ruok.lottrey.retrofitModule.response.LotteryStatOneResponse;
import com.lottery.ruok.lottrey.ui.component.PrizeHistoryHeaderItemView;

import java.util.Iterator;
import java.util.List;

/**
 * Created by ASUS on 2017/7/26.
 */

public class PrizeHistoryhorizontalAdapter extends BaseAppRecyclerViewAdapter<LotteryStatOneResponse.ItemListBeans> {
    public LotteryStatOneResponse datas;


    public PrizeHistoryhorizontalAdapter(Context context, LotteryStatOneResponse datas) {
        super(context, null);
        this.datas = datas;
    }

    public PrizeHistoryhorizontalAdapter(Context context, List<LotteryStatOneResponse.ItemListBeans> list, LotteryStatOneResponse datas) {
        super(context, list);
        this.datas = datas;
    }

    public void setDatas(LotteryStatOneResponse data) {
        datas = data;
        updateTimeData();
    }

    private void updateTimeData() {
        List<LotteryStatOneResponse.ItemListBeans> list = getList();
        if (list != null) {
            Iterator<LotteryStatOneResponse.ItemListBeans> iterator = list.iterator();
            while (iterator.hasNext()) {
                LotteryStatOneResponse.ItemListBeans next = iterator.next();
                if (next != null) {
                    next.setTime(datas.getTime());
                }
            }
        }
    }


    @Override
    protected View createItemView(Context mContext, int viewType) {
        return new PrizeHistoryHeaderItemView(mContext);
    }

    @Override
    protected void onBindView(View itemView, int position) {
        if (itemView instanceof PrizeHistoryHeaderItemView) {
            PrizeHistoryHeaderItemView view = (PrizeHistoryHeaderItemView) itemView;
            view.setData(getList().get(position), datas);
        }
    }


}
